using Transferomatic.Views;
using System;
using System.Windows.Forms;
using System.Globalization;
using Transferomatic.Enumerators;

namespace Transferomatic.ApplicationControllers
{
    public partial class Controller
    {
        #region Methods
        private ExtendedDialogResult ConfirmationDialogView_Show(
            MainView theParentView,
            string theMessage)
        {
            // Instantiate an instance
            ConfirmationDialogView theView = new ConfirmationDialogView();

            theView.buttonOverwrite.Click +=
                new EventHandler(ConfirmationDialogView_buttonOverwrite_Click);
            theView.buttonIgnore.Click +=
                new EventHandler(ConfirmationDialogView_buttonIgnore_Click);

            theView.labelMessage.Text = theMessage;

            // Show the form
            theView.ShowDialog(theParentView);

            return theView.ExtendedDialogResult;
        }

        #region Event Handlers
        private void ConfirmationDialogView_buttonOverwrite_Click(
            object sender,
            EventArgs e)
        {
            Application.DoEvents();

            Button theOverwriteButton = sender as Button;
            ConfirmationDialogView theParentView =
                theOverwriteButton.FindForm() as ConfirmationDialogView;

            theParentView.ExtendedDialogResult = 
                theParentView.checkboxApplyToAll.Checked
                ? ExtendedDialogResult.OverwriteAll
                : ExtendedDialogResult.Overwrite;

            theParentView.Close();
        }

        private void ConfirmationDialogView_buttonIgnore_Click(
            object sender,
            EventArgs e)
        {
            Application.DoEvents();

            Button theIgnoreButton = sender as Button;
            ConfirmationDialogView theParentView =
                theIgnoreButton.FindForm() as ConfirmationDialogView;

            theParentView.ExtendedDialogResult =
                theParentView.checkboxApplyToAll.Checked
                ? ExtendedDialogResult.IgnoreAll
                : ExtendedDialogResult.Ignore;

            theParentView.Close();
        }
        #endregion
        #endregion
    }
}
